package com.keta.foundation.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(name = "t_permission")
public class Permission {
	
	//用于菜单显示
	public final static String PERMISSION_SHOW = "show";
	
	public final static String PERMISSION_CREATE = "create";
	
	public final static String PERMISSION_VIEW = "view";
	
	public final static String PERMISSION_EDIT = "edit";
	
	public final static String PERMISSION_DELETE = "delete";

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@NotBlank
	@Column(length = 64, nullable = false)
	private String name;

	@NotBlank
	@Column(length = 16, nullable = false)
	private String sn;

	@Column(length = 256, nullable = true)
	private String description;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "moduleId")
	private Module module;

	@OneToMany(mappedBy = "permission")
	private List<RolePermission> rolePermissions;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * 获取权限名称
	 * 
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * 设置权限名称
	 * 
	 * @return
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 获取权限操作名称 (授权码)
	 * 
	 * @return
	 */
	public String getSn() {
		return sn;
	}

	/**
	 * 设置权限操作名称 (授权码)
	 * 
	 * @return
	 */
	public void setSn(String sn) {
		this.sn = sn;
	}

	/**
	 * 获取权限描述
	 * 
	 * @return
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * 设置权限描述
	 * 
	 * @return
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * 获取权限所在模块
	 * 
	 * @return
	 */
	public Module getModule() {
		return module;
	}

	/**
	 * 设置权限所在模块
	 * 
	 * @return
	 */
	public void setModule(Module module) {
		this.module = module;
	}

	public List<RolePermission> getRolePermissions() {
		return rolePermissions;
	}

	public void setRolePermissions(List<RolePermission> rolePermissions) {
		this.rolePermissions = rolePermissions;
	}

}
